package com.xiaobawang.xjsyy_idea_plugin.global;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author synhard
 * @description 插件全局配置
 * @date 2024/5/22 10:56
 * @email songxinhang2023@e-chinalife.com
 * @id 18101119
 * @phone 13001321080
 */
public class GlobalConfig {

    public static String token = "";
    public static String gitRepo = "";
    public static String appName = "";
    public static Map<String, String> org2Id = new HashMap<>(10);
    public static Map<String, String> id2Org = new HashMap<>(10);
    public static String curOrgId = "";
    public static List<String> appNameList = new ArrayList<>();
    public static final String YUNXIAO_DOMAIN = "https://poctest.yunxiao.clic/oapi/v1";
    public static final String RELEASE_WORK_FLOWS = "/appstack/organizations/%s/apps/%s/releaseWorkflows";
    public static final String PIPELINE_DETAIL = "/flow/organizations/%s/pipelines/%s";
    public static final String RUNNING_HISTORY = "/flow/organizations/%s/pipelines/%s/runs";
    public static final String RUNNING_DETAIL = "/flow/organizations/%s/pipelines/%s/runs/%s";
    public static final String RUN_PIPELINE = "/appstack/organizations/%s/apps/%s/releaseWorkflows/%s/releaseStages/%s:execute";
    public static Map<Integer, String> triggerModeMap = new HashMap<>(6);

    static {
        org2Id.put("研发中心", "77f6b83b-02b7-442a-8ea1-8998d68a9128");
        org2Id.put("杭州研发分中心", "6ff27494-10f3-45f0-9c2b-67a83c9c727a");
        org2Id.put("深圳分公司", "918efcdb-8d40-4db4-be2b-b1941003aff5");
        for (Map.Entry<String, String> entry : org2Id.entrySet()) {
            id2Org.put(entry.getValue(), entry.getKey());
        }

        triggerModeMap.put(1, "人工触发");
        triggerModeMap.put(2, "定时触发");
        triggerModeMap.put(3, "代码提交触发");
        triggerModeMap.put(5, "流水线触发");
        triggerModeMap.put(6, "WEBHOOK触发");
    }

    public static boolean checkToken() {
        return !StringUtils.isEmpty(token);
    }

    public static boolean checkGitRepo() {
        return !StringUtils.isEmpty(gitRepo);
    }

    public static boolean checkAppName() {
        return !StringUtils.isEmpty(appName);
    }
}
